//
//  GQHMessageModel.m
//  Xanthium
//
//  Created by GuanQinghao on 20/05/2018.
//  Copyright © 2018 GuanQinghao. All rights reserved.
//

#import "GQHMessageModel.h"
#import "GQHHeader.h"


@implementation GQHMessageModel

+ (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
    
    return @{
             @"qh_messageID" : @"messageId",
             @"qh_userID" : @"userId",
             @"qh_readState" : @"checkState",
             @"qh_readTime" : @"checkTime",
             @"qh_messageTypeKey" : @"newsCategory",
             @"qh_messageContent" : @"messageContent",
             @"qh_messageState" : @"messageState"
             
             };
}

///  获取消息列表
+ (void)qh_fetchMessagesWithParameters:(NSDictionary *)parameters success:(void(^)(BOOL status, NSNumber *code, NSString *message, NSArray<GQHMessageModel *> *messages))success failure:(void(^)(NSError *error))failure {
    
    NSString *URLString = [[NSString qh_APIURLString] stringByAppendingPathComponent:@"/buMessageReceiveUser/1/list"];
    [GQHNetHelper qh_requestGET:URLString parameters:parameters success:^(NSNumber *code, NSString *message, NSDictionary *data) {
        DLog(@"%@---%@---%@",code,message,data);
        
        if (0 == [code integerValue]) {
            
            NSMutableArray *messageArray = [NSMutableArray array];
            for (NSDictionary *object in [data objectForKey:@"rows"]) {
                
                GQHMessageModel *messageModel = [GQHMessageModel yy_modelWithDictionary:object];
                if (messageModel) {
                    
                    CGSize size = AUTO_SIZE(CGSizeMake(GQH_SCREEN_WIDTH - GQH_MARGIN_DOUBLE, MAXFLOAT), messageModel.qh_messageContent, kSmallerFont);
                    messageModel.qh_rowHeight = size.height;
                    
                    [messageArray addObject:messageModel];
                }
            }
            success(YES,code,message,messageArray);
        } else {
            
            success(NO,code,message,nil);
        }
    } failure:^(NSError *error) {
        
        failure(error);
    }];
}

@end
